package com.example.mobiledatapackage.controller;

import com.example.mobiledatapackage.domain.Package;
import com.example.mobiledatapackage.mapStruct.PackageMapStruct;
import com.example.mobiledatapackage.request.pkg.DeletePackageInfo;
import com.example.mobiledatapackage.request.pkg.ModifyPackageInfo;
import com.example.mobiledatapackage.request.pkg.PackageCondition;
import com.example.mobiledatapackage.service.PackageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/pkg")
@Slf4j
@Tag(name = "PackageController", description = "用于对套餐数据进行增删查改的接口")
public class PackageController {

    @Autowired
    private PackageService packageService;

    @Resource
    private PackageMapStruct packageMapStruct;

    @GetMapping("/select")
    @Operation(summary = "查询符合条件的套餐")
    public List<Package> selectPkgConditional(PackageCondition packageCondition) {
        return packageService.selectConditional(packageCondition);
    }

    @PostMapping("/insert")
    @Operation(summary = "插入套餐数据")
    public void insertPkg(@RequestBody @Validated Package pkg) {
        packageService.insert(pkg);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除某条套餐")
    public void deletePkg(@RequestBody @Validated DeletePackageInfo deletePackageInfo) {
        packageService.deleteByPrimaryKey(deletePackageInfo.getPkgId());
    }

    @PostMapping("/modify")
    @Operation(summary = "修改套餐数据")
    public void modifyPkg(@RequestBody @Validated ModifyPackageInfo modifyPkgInfo) {
        Package pkg = packageMapStruct.modifyInfoToPkg(modifyPkgInfo);
        packageService.updateByPrimaryKeySelective(pkg);
    }

}
